package org.peterf.foxish.engine.setting;

import android.view.View.MeasureSpec;

public class RatioScreenSetting extends ScreenSetting {

    private float ratio;

    public RatioScreenSetting(float ratio) {
        this.ratio = ratio;
    }

    @Override
    public int[] getMeasuredSize(int widthMeasureSpec, int heightMeasureSpec) {
        int w = MeasureSpec.getSize(widthMeasureSpec);
        int h = MeasureSpec.getSize(heightMeasureSpec);
        if ((float) w / h < ratio) {
            screenSize[0] = w;
            screenSize[1] = Math.round(w / ratio);
        } else {
            screenSize[0] = Math.round(h * ratio);
            screenSize[1] = h;
        }
        return screenSize;
    }

}
